from django.utils.deprecation import MiddlewareMixin

class MD1Middleware(MiddlewareMixin):

    def process_request(self, request):
        print("md1  process_request 方法。", id(request))  # 在视图之前执行

    def process_response(self, request, response):
        # 基于请求响应
        print("md1  process_response 方法！", id(request))  # 在视图之后
        return response